home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / microcrn / issue_41.arc / TURKKEYS.ARC / TURKKEYS.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-03-10  |  5.9 KB  |  209 lines

  1. ;**     Code from 86world column in Micro Cornucopia Magazine Issue #41
  2. ;**
  3. ;**
  4. ;***************************************************************************
  5. ;**    TURKKEYS.ASM - a program to demonstrate how to trap the INT 16h     **
  6. ;**        keyboard by translating several alt+<key> and         **
  7. ;**        alt+shift+<key> combinations into accented characters     **
  8. ;**        used in the Turkish alphabet but not present on the      **
  9. ;**        standard IBM keyboard.                     **
  10. ;**                                     **
  11. ;**        For example, alt+c becomes (c with cedilla)         **
  12. ;**        and alt+shift+c (alt+C) becomes (capital C w/cedilla)     **
  13. ;**                                     **
  14. ;**    TO ASSEMBLE:    MASM TURKKEYS;                     **
  15. ;**            LINK TURKKEYS;                     **
  16. ;**            EXE2BIN TURKKEYS TURKKEYS.COM             **
  17. ;**            ERASE TURKKEYS.EXE (and TURKKEYS.OBJ)         **
  18. ;**                                     **
  19. ;**    NOTES:    Obviously, not many people have a burning need to type     **
  20. ;**        Turkish text. What's important here is the method, which **
  21. ;**        can be used for any number of other things. All         **
  22. ;**        translations are controlled by the tables XLATE and     **
  23. ;**        SHIFTXLATE, making it possible to translate nearly     **
  24. ;**        anything to anything.                     **
  25. ;**                                     **
  26. ;**        "Use it as you will" Laine Stump, Feb. 13, 1988     **
  27. ;**                         (orig. Feb, 1986)     **
  28. ;**************************************************************************
  29. ;       macro definitions and other constants
  30.     INCLUDE        MSDOS.MAC
  31.  
  32. Keyboard    equ    16h
  33.  conin    equ    0    ;function code to put in AH
  34.  constat    equ    1
  35.  shiftstat    equ    2
  36.     ctrl    equ    00000100b ;shift bits returned in AL
  37.     alt    equ    00001000b
  38.     shifts    equ    00000011b
  39.     caps    equ    01000000b
  40. ;
  41. ;***************************************************************************
  42. CODE    SEGMENT PUBLIC
  43.     ASSUME    CS:CODE
  44. FirstByte    equ    this byte    ;between here & LastByte remains res.
  45.  
  46.     ORG    100h
  47. START:    JMP    INIT        ;init code is at end so we can get rid of it.
  48.  
  49. OldKbdInt    equ    this dword
  50.  OldKbdIntOfs    DW    ?
  51.  OldKbdIntSeg    DW    ?
  52. ;
  53. ;***************************************************************************
  54. ;    input translation table for 16 bit IBM character codes
  55. ;
  56. ;    first word of a pair is original 16 bit character code (see
  57. ;    the Pink Shirt book for details), second word is its xlation
  58. ;    End of table indicated by a 0 word.
  59. ;
  60. ;    Characters marked by ** are not present in the standard IBM
  61. ;    Extended Character Set and require a new character generator ROM
  62. ;    to function properly.
  63. ;
  64. Xlate    DW    1600h,1681h    ;umlaut u
  65.     DW    1700h,178Dh    ;undotted i **
  66.     DW    1800h,1894h    ;umlaut o
  67.     DW    1E00h,1E83h    ;circumflex a
  68.     DW    1F00h,1F9Fh    ;cedilla s **
  69.     DW    2200h,22A7h    ;soft g **
  70.     DW    2E00h,2E87h    ;cedilla c
  71.     DW    0        ;end of table
  72. ;
  73. ;    translation table used if a <shift> key is depressed
  74. ;
  75. ShiftXlate DW    1600h,169Ah    ;umlaut U
  76.     DW    1700h,1798h    ;dotted I **
  77.     DW    1800h,1899h    ;umlaut O
  78.     DW    1E00h,1E8Eh    ;circumflex A **
  79.     DW    1F00h,1F9Eh    ;cedilla S **
  80.     DW    2200h,22A6h    ;soft G **
  81.     DW    2E00h,2E80h    ;cedilla C
  82.     DW    0        ;end of table
  83. ;
  84. ;*******************************************************************
  85. ;    translate 16 bit character in AX according to Xlate table
  86. ;
  87. KeyXlate:
  88.     CALL    AltDown?    ;xlate only if "alt" is not down
  89.     JNZ    KeyXlate9    ;(actually if alt+ctl is not down)
  90.     PUSH    BX        ;(since we have modified shiftstat)
  91.     MOV    BX,offset Xlate
  92.     CALL    ShiftDown?
  93.     JZ    KeyXlate1
  94.     MOV    BX,offset ShiftXlate
  95. KeyXlate1:
  96.     CMP    word ptr CS:[BX],0    ;WHILE not end of table
  97.     JE    KeyXlate3
  98.     CMP    CS:[BX],AX        ; AND not found
  99.     JE    KeyXlate2
  100.      ADD     BX,4            ; tableptr++
  101.      JMP     KeyXlate1
  102. KeyXlate2:
  103.     MOV    AX,CS:[BX+2]        ;IF found, replace original
  104. KeyXlate3:
  105.     POP    BX
  106. KeyXlate9:
  107.     RET
  108. ;
  109. ;*******************************************************************
  110. NewKbdInt:    ;This is where all INT 16s now go
  111.     STI
  112.     CMP    AH,shiftstat
  113.     JZ    ShiftStatFunction
  114.     CMP    AH,constat
  115.     JZ    ConStatFunction
  116.     CMP    AH,conin
  117.     JZ    ConinFunction
  118.     JMP    OldKbdInt    ;pass unknown functions on
  119. ;
  120. ;*******************************************************************
  121. ConinFunction:
  122.     PUSHF            ;simulate INT 16h
  123.     CALL    OldKbdInt    ;to get a character
  124.     CALL    KeyXlate
  125.     IRET
  126. ;
  127. ;*******************************************************************
  128. ConStatFunction    PROC FAR
  129.     PUSHF    ;call original stat routine
  130.     CALL    OldKbdInt
  131.     JZ    ConStat9
  132.     PUSHF    ;save to return to calling program
  133.     CALL    KeyXlate
  134.     POPF
  135. ConStat9:
  136.     RET    2        ;instead of IRET so caller gets flags
  137. ConStatFunction ENDP
  138. ;
  139. ;*******************************************************************
  140. ShiftStatFunction:
  141.     PUSHF    ;simulate an INT
  142.     CALL    OldKbdInt
  143.     TEST    AL,alt        ;see if alt key is down
  144.     JZ    ShiftStat9    ; we will only show alt if also ctrl
  145.     AND    AL,NOT alt    ; assume no ctrl
  146.     TEST    AL,ctrl
  147.     JZ    ShiftStat9
  148.     OR    AL,alt        ; else turn alt on & ctrl off
  149.     AND    AL,NOT ctrl
  150. ShiftStat9:
  151.     IRET
  152. ;
  153. ;*******************************************************************
  154. ;    ask ROM BIOS about state of shift keys
  155. ;    returns NZ if left or right shift is down, or if capslock is on
  156. ;
  157. ShiftDown?:
  158.     PUSH    AX
  159.     PUSH    BX
  160.     MOV    AH,shiftstat
  161.     INT    Keyboard    ;HEY! Are we reentrant or what??
  162.     TEST    AL,shifts
  163.     JZ    SHIFTDOWN2
  164.      NOT     AL
  165. SHIFTDOWN2:
  166.     TEST    AL,caps
  167.     POP    BX
  168.     POP    AX
  169.     RET
  170. ;
  171. ;*******************************************************************
  172. AltDown?:    ;test status of alt key
  173.     PUSH    AX
  174.     PUSH    BX
  175.     MOV    AH,shiftstat
  176.     INT    Keyboard
  177.     TEST    AL,alt
  178.     POP    BX
  179.     POP    AX
  180.     RET
  181. ;
  182. LastByte    equ    this byte
  183. ;************************************************************************
  184. ;    Below this point only used during initialization, then discarded
  185. ;
  186.     ASSUME    DS:CODE
  187. Msg    DB    'TURKKEYS input translator 02/13/88<lrs>',CR,LF
  188. MsgLen    = ($-Msg)
  189.  
  190. INIT:    Output    stdout,Msg,MsgLen
  191.  
  192.     MOV    AL,Keyboard        ;get the original INT 16h vector
  193.     DOS    GetVector
  194.     MOV    OldKbdIntOfs,BX        ;save to call later
  195.     MOV    OldKbdIntSeg,ES
  196.  
  197.     MOV    AL,Keyboard        ;install our own vector
  198.     MOV    DX,offset NewKbdInt
  199.     DOS    SetVector
  200.  
  201.     MOV DX,(LastByte-FirstByte+15)/16
  202.     MOV    AL,0
  203.     DOS    TerminateKeep
  204.  
  205. CODE    ENDS
  206.     END    START
  207.  
  208.  
  209.